import type { TooltipProps } from 'naive-ui'

export interface FormConfigElementRule {
  required?: boolean
  pattern?: RegExp | string
  min?: number
  max?: number
  len?: number
  message?: string
  trigger?: string | string[]
  level?: 'warning' | 'error'
  validator?: (rule: FormConfigElementRule, value: any) => boolean | Error
  stringFunctionFields?: string[]
}

export interface FormConfigItemProps {
  label?: string
  labelWidth?: string
  labelStyle?: string
  labelAlign?: 'left' | 'center' | 'right'
  labelPlacement?: 'left' | 'top'
  path?: string
  size?: 'small' | 'medium' | 'large'
  requireMarkPlacement?: 'left' | 'right' | 'right-hanging'
  rule?: FormConfigElementRule | FormConfigElementRule[]
}

export interface FormConfigElementProps {
  value?: any
  onUpdateValue?: string | string[] | Function | Function[]
  formattedValue?: any
  onUpdateFormattedValue?: string | string[] | Function | Function[]
}

export interface FormConfigPromptProps {
  content: string
  tooltip?: TooltipProps
}

export interface FormConfigElement {
  id: number
  type: string
  formItemProps?: FormConfigItemProps
  elementProps?: FormConfigElementProps
  promptProps?: FormConfigPromptProps
}

export type FormConfigSubset = Record<string, FormConfigElement[]>

export interface FormConfigModel {
  id: number
  title?: string | null
  elements: FormConfigElement[]
  subset?: FormConfigSubset
}
